﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using RBS.Common;
using RBS.Core.Model;
namespace RBS.Core.BLL {
	 	//U_User
		public partial class U_User
	{
   		     
		private readonly RBS.Core.DAL.U_User dal=new RBS.Core.DAL.U_User();
		public U_User()
		{}
		
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int Id)
		{
			return dal.Exists(Id);
		}
        public bool Exists(string Id)
        {
            return dal.Exists(Id);
        }

		    public bool IsReg(string mail)
		    {
                return dal.IsReg(mail);
		    }

		    /// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(RBS.Core.Model.U_User model)
		{
						return dal.Add(model);
						
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(RBS.Core.Model.U_User model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{
			
			return dal.Delete(Id);
		}
				/// <summary>
		/// 批量删除一批数据
		/// </summary>
		public bool DeleteList(string U_Idlist )
		{
			return dal.DeleteList(U_Idlist );
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public RBS.Core.Model.U_User GetModel(int Id)
		{
			
			return dal.GetModel(Id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public RBS.Core.Model.U_User GetModelByCache(int Id)
		{
			
			string CacheKey = "U_UserModel-" + Id;
			object objModel = RBS.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(Id);
					if (objModel != null)
					{
						int ModelCache = RBS.Common.ConfigHelper.GetConfigInt("ModelCache");
						RBS.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (RBS.Core.Model.U_User)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<RBS.Core.Model.U_User> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<RBS.Core.Model.U_User> DataTableToList(DataTable dt)
		{
			List<RBS.Core.Model.U_User> modelList = new List<RBS.Core.Model.U_User>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				RBS.Core.Model.U_User model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new RBS.Core.Model.U_User();					
													if(dt.Rows[n]["Id"].ToString()!="")
				{
					model.Id=int.Parse(dt.Rows[n]["Id"].ToString());
				}
																																				model.U_Name= dt.Rows[n]["U_Name"].ToString();
																																model.Nick_Name= dt.Rows[n]["Nick_Name"].ToString();
																																model.U_Uid= dt.Rows[n]["U_Uid"].ToString();
																																model.PassWord= dt.Rows[n]["PassWord"].ToString();
																																model.Email= dt.Rows[n]["Email"].ToString();
																																model.Telphone= dt.Rows[n]["Telphone"].ToString();
																																model.Mobile= dt.Rows[n]["Mobile"].ToString();
																																model.Sex= dt.Rows[n]["Sex"].ToString();
																												if(dt.Rows[n]["Birthday"].ToString()!="")
				{
					model.Birthday=DateTime.Parse(dt.Rows[n]["Birthday"].ToString());
				}
																																				model.QQ= dt.Rows[n]["QQ"].ToString();
																												if(dt.Rows[n]["Exp"].ToString()!="")
				{
					model.Exp=int.Parse(dt.Rows[n]["Exp"].ToString());
				}
																																if(dt.Rows[n]["Status"].ToString()!="")
				{
					model.Status=int.Parse(dt.Rows[n]["Status"].ToString());
				}
																																if(dt.Rows[n]["Reg_Time"].ToString()!="")
				{
					model.Reg_Time=DateTime.Parse(dt.Rows[n]["Reg_Time"].ToString());
				}
																																				model.Reg_IP= dt.Rows[n]["Reg_IP"].ToString();
																						
				
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
#endregion


	    #region  ExtensionMethod
	    public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
	    {
            return dal.GetList(pageSize, pageIndex, strWhere, filedOrder, out recordCount);
	    }

	    #endregion  ExtensionMethod


        public Model.U_User Login(string name, string pwd)
        { 
            return dal.Login(name, pwd);
        }



		    /// <summary>
		    /// 获取用户代办
		    /// </summary>
		    /// <param name="userId"></param>
		    /// <returns></returns>
		    public DataTable GetUserMain(int userId)
		    {
		        return dal.GetUserMain(userId);
		    }
	}
}